package com.linjian.togetherbirthday.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.linjian.togetherbirthday.R;
import com.linjian.togetherbirthday.base.BaseFragment;
import com.linjian.togetherbirthday.chat.ChattingAllActivity;
import com.linjian.togetherbirthday.chat.ConversationFragment;
import com.linjian.togetherbirthday.utils.NoticeEvent;
import com.yuntongxun.plugin.common.common.utils.TextUtil;
import com.yuntongxun.plugin.im.manager.IMPluginManager;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class HomeThreeFragment extends BaseFragment implements View.OnClickListener {

    private TextView textView1,textView2,textView3;

    public static HomeThreeFragment newInstance() {
        HomeThreeFragment homeOneFragment = new HomeThreeFragment();
        Bundle bundle = new Bundle();
//        bundle.putInt(Integer.class.getName(), resId);
        homeOneFragment.setArguments(bundle);
        return homeOneFragment;
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        EventBus.getDefault().register(this);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            getActivity().getWindow().getDecorView().setSystemUiVisibility( View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }
    }

    @Override
    protected int setView() {
        return R.layout.fragment_home_three;
    }

    @Override
    protected void init(View view) {
        getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.chat_frame, new ConversationFragment())
                .commit();
        textView1 = view.findViewById(R.id.test1);
        textView2 = view.findViewById(R.id.test2);
        textView3 = view.findViewById(R.id.test3);
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        textView1.setOnClickListener(this);
        textView2.setOnClickListener(this);
        textView3.setOnClickListener(this);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void OnEventMsg(NoticeEvent event){

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.test1:
                //发起点对点聊天
                String recipients = "123456789";
                if (TextUtil.isEmpty(recipients)) {
                    return;
                }
                IMPluginManager.getManager().startChatting(getActivity(), recipients);
                break;
            case R.id.test2:
                //我的沟通页面
                Intent intent1 = new Intent(getActivity(), ConversationFragment.class);
                startActivity(intent1);
                break;
            case R.id.test3:
                //邀请群组并会话
                Intent intent2 = new Intent(getActivity(), ChattingAllActivity.class);
                startActivity(intent2);
                break;
        }
    }
}
